/***********************************************************************
 * Module:  Diplome.java
 * Author:  Alexandro
 * Purpose: Defines the Class Diplome
 ***********************************************************************/

package dao;

import java.util.*;
import java.sql.*;

public class Diplome extends Codage implements InterfaceDAO {
   private int niveau;
   
   public Annee[] annee;
   public Filiere[] filiere;
   
   public int getNiveau() {
      return niveau;
   }
   
   /** @param newNiveau */
   public void setNiveau(int newNiveau) {
      niveau = newNiveau;
   }
   
   public int insert(int[] fk) {
      
      try {			
			dao.DAODataConnection.executer("INSERT INTO diplome VALUES("+getCode()+",'"+getLibelle()+"',"+getNiveau()+");");											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }
   
   public Object[] select(int[] param) {
      
       try {			
			
			ResultSet tabla = dao.DAODataConnection.executerQuery("SELECT * FROM diplome");								
			int max = 10;
			Diplome[] sortie = new Diplome[max];
			int i=0;
			while(tabla.next() && i<max)	
			{
				Diplome neuf = new Diplome();
				neuf.setCode(tabla.getInt(1));
				neuf.setLibelle(tabla.getString(2));
				neuf.setNiveau(tabla.getInt(3));
				sortie[i]=neuf;
				i++;
			}		
			return sortie;			
			}
		catch(Exception e){ System.out.println(e); }		
		
		return null;
		
   }
   
   public int delete(int[] param) {
      
      try {			
			dao.DAODataConnection.executer("DELETE FROM diplome WHERE code_dip="+getCode());											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }
   
   public int update(int[] fk) {
        try {			
        	if (fk == null)
			dao.DAODataConnection.executer("UPDATE filiere SET libelle='"+getLibelle()+"' where code_fil="+getCode());											
			else 
			dao.DAODataConnection.executer("INSERT DIPLOME_FILIERE VALUES("+fk[0]+","+fk[1]+")");											
			return 0;			
			}
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
   }

}